package cn.huaqingcheng.tool.http;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Accessors;

import java.net.http.HttpClient;

/**
 *
 */
@Getter
@Accessors(fluent = true)
@RequiredArgsConstructor
@SuppressWarnings("ClassNamePrefixedWithPackageName")
public enum HttpVersion {
    /**
     * @see <a href="https://www.rfc-editor.org/rfc/rfc1945.html">RFC 1945</a>
     */
    HTTP_1("1"),
    /**
     * @see <a href="https://www.rfc-editor.org/rfc/rfc2068.html">RFC 2068</a>
     */
    HTTP_1_1("1.1"),
    /**
     * @see <a href="https://www.rfc-editor.org/rfc/rfc7540.html">RFC 7540</a>
     */
    HTTP_2("2"),
    /**
     * @see <a href="https://www.rfc-editor.org/rfc/rfc9114.html">RFC 9114</a>
     */
    HTTP_3("3");


    private final String display;

    public static HttpVersion of(HttpClient.Version version) {
        return switch (version) {
            case HTTP_1_1 -> HTTP_1_1;
            case HTTP_2 -> HTTP_2;
        };
    }

    @Override
    public String toString() {
        return "HTTP/" + display;
    }
}
